#!/usr/bin/python3
# -*- coding: utf-8 -*-

'''
简单的拖放
'''

import sys
from PyQt5.QtWidgets import (QWidget,
                             QPushButton,
                             QLineEdit,
                             QApplication)


class Button(QPushButton):
    def __init__(self, title, parent):
        super(Button, self).__init__(title, parent)

        self.setAcceptDrops(True)

    def dragEnterEvent(self, event):
        if event.mimeData().hasFormat("text/plain"):
            event.accept()
        else:
            event.ignore()

    def dropEvent(self, event):
        self.setText(event.mimeData().text())


class Example(QWidget):
    def __init__(self):
        super(Example, self).__init__()

        self.initUI()

    def initUI(self):
        edit = QLineEdit("", self)
        edit.setDragEnabled(True)
        edit.move(30, 65)

        button = Button("Button", self)
        button.move(190, 65)

        self.setWindowTitle("Simple drag and drop")
        self.setGeometry(300, 300, 300, 150)
        self.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
